<?php
include('../Class/SanPham_Class.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Xóa sản phẩm </title>
<head>
</head>

<body>
<form action="Delete_SanPham.php" method="post">
<div>Danh Sách Sản Phẩm</div>
<div><a href="Add_SanPham.php">Thêm Sản Phẩm</a></div>
<?php
	$sanpham=new SanPham();
	$sql=$sanpham->GetAll_SanPham();
	echo '<table  border="1" >';
	echo '<tr>';
	echo '<td>Mã Sản Phẩm</td> <td>Tên Sản Phẩm</td> <td>Hình Ảnh</td> <td>Giá</td> <td>Mã NSX</td> <td>Xóa / Sửa</td>';
	echo '</tr>';
	if (isset($_GET['p'])) $pindex = $_GET['p']; else $pindex = 1;
				$psize = 30;
				$sanpham=new SanPham();
				$sql = $sanpham->get_by_page($psize,$pindex);
				$str_p = $sanpham->print_page();
		while($row=@mysql_fetch_array($sql))
			{
			echo '<tr>';
			echo '<td>'.$row['MaSP'].'</td>';
			echo '<td>'.$row['TenSP'].'</td>';
			echo '<td>'.$row['HinhAnh'].'</td>';
			echo '<td>'.$row['Gia'].'</td>';
			echo '<td>'.$row['MaNSX'].'</td>';
			echo '<td><a href=Delete_SanPham.php?id='.$row['MaSP'].'>Xóa</a> / <a href=Update_SanPham.php?id='.$row['MaSP'].'>Sửa</a></td>';
			echo '</tr>';
			}
	echo '</table>';
	echo "<div align='left'>Page ".$str_p."</div>";
?>

</form>
<?php
if(isset($_GET['id']))
{
	$id=$_GET['id'];
	if($sanpham->Delete_SanPham($id)>0)
	{
		echo "Xóa thành công !!";
		header('location: Delete_SanPham.php');
	}
	else
	{
		echo "Xóa thất bại vui lòng kiểm tra lại!!".@mysql_error();
	}
}
?>

</body>

</html>
